//
//  GetAddressRequeset.swift
//  d11
//
//  Created by rhonin on 2018/11/1.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
import SwiftyJSON
class GetAddressRequeset: NSObject {
    var blockA : (([JSON])->())?
    static let stringAddressLoad = "loadingAdress"
    static let stringAddressStopLoad = "stoploadingAdress"
    func requesetForProvic(block:@escaping ([JSON])->()){
      //  weak var this = self
        NotificationCenter.default.post(name:  NSNotification.Name(rawValue: GetAddressRequeset.stringAddressLoad), object: nil, userInfo: nil)
        RequestHelper.post(atPath: "/clientsAPIs/GetAddressProvince", withData: Dictionary(), withCompletion: { data in
             NotificationCenter.default.post(name:  NSNotification.Name(rawValue: GetAddressRequeset.stringAddressStopLoad), object: nil, userInfo: nil)
            let json = JSON(data)
            if json.arrayValue.count > 0{
               block(json.arrayValue)
            }
        })
    }
    
    func requesetForCIty(code:String,block:@escaping ([JSON])->()) {
         NotificationCenter.default.post(name:  NSNotification.Name(rawValue: GetAddressRequeset.stringAddressLoad), object: nil, userInfo: nil)
        RequestHelper.post(atPath: "/clientsAPIs/GetAddressCity", withData: ["code":code], withCompletion: { data in
             NotificationCenter.default.post(name:  NSNotification.Name(rawValue: GetAddressRequeset.stringAddressStopLoad), object: nil, userInfo: nil)
            let json = JSON(data)
            if json["data"].arrayValue.count > 0{
                block(json["data"].arrayValue)
            }
        })
    }
    func requesetForArea(code:String,block:@escaping ([JSON])->()) {
         NotificationCenter.default.post(name:  NSNotification.Name(rawValue: GetAddressRequeset.stringAddressLoad), object: nil, userInfo: nil)
        RequestHelper.post(atPath: "/clientsAPIs/GetAddressArea", withData: ["code":code], withCompletion: { data in
            NotificationCenter.default.post(name:  NSNotification.Name(rawValue: GetAddressRequeset.stringAddressStopLoad), object: nil, userInfo: nil)
            let json = JSON(data)
            if json["data"].arrayValue.count > 0{
                block(json["data"].arrayValue)
            }
        })
    }
    
    func requesetForStreet(code:String,block:@escaping ([JSON])->()) {
         NotificationCenter.default.post(name:  NSNotification.Name(rawValue: GetAddressRequeset.stringAddressLoad), object: nil, userInfo: nil)
        RequestHelper.post(atPath: "/clientsAPIs/GetAddressStreet", withData: ["code":code], withCompletion: { data in
            NotificationCenter.default.post(name:  NSNotification.Name(rawValue: GetAddressRequeset.stringAddressStopLoad), object: nil, userInfo: nil)
            let json = JSON(data)
            if json["data"].arrayValue.count > 0{
                block(json["data"].arrayValue)
            }
        })
    }
}
